<?php
namespace Controller;
use Kuyuan\WqCore\controller\Controller;
use Model\RedFormModel;

/**
 * 万能表单
 * Class Enter
 * @package Controller
 */
class RedForm extends Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 新增红包表单
     * @param $_data
     * @return mixed
     */
    public function add($_data)
    {
        if(
            !RedFormModel::where("uid",$this->_uid)
            ->where("red_id",$_data["red_id"])
            ->value("id")
        ) {
            $_data["uniacid"] = $this->_uniacid;
            $_data["uid"] = $this->_uid;
            return RedFormModel::create($_data);
        } else {
            return true;
        }
    }

    /**
     * 获取列表
     * @param $_red_id
     * @param array $_limit
     * @return mixed
     */
    public function getList($_red_id,Array $_limit = array())
    {
        $RedForm = RedFormModel::where("red_id",$_red_id)
            ->field(array("uid","form_content","create_time"))
            ->order("create_time","desc")
            ->cache(!KUYUAN_DEBUG);
        if(count($_limit) > 1) {
            $RedForm->limit($_limit[0],$_limit[1]);
        }
        return $RedForm->select();
    }
}